#
# Copyright (c) 2023, NVIDIA CORPORATION.  All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

set(CMAKE_CXX_VISIBILITY_PRESET default)
set(CMAKE_C_VISIBILITY_PRESET default)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 0)

add_compile_definitions(NVML_NO_UNVERSIONED_FUNC_DEFS)

add_library(nvmli_public OBJECT)
target_link_libraries(
    nvmli_public
    PRIVATE
        nvmli_interface
        sdk_nvml_interface
)

target_sources(nvmli_public
    PRIVATE
        InjectionArgument.cpp
        InjectionKeys.cpp
        nvml_generated_stubs.cpp
        nvml_stubs.cpp
)

add_library(nvml_injection SHARED)
set_target_properties(nvml_injection PROPERTIES LINKER_LANGUAGE CXX)

target_sources(
    nvml_injection
    PRIVATE
        AttributeQueryInfo.cpp
        CompoundValue.cpp
        FieldHelpers.cpp
        InjectedNvml.cpp
        PassThruNvml.cpp
)

target_link_libraries(nvml_injection PUBLIC nvmli_interface)
target_link_libraries(nvml_injection PRIVATE nvmli_public sdk_nvml_interface)
target_include_directories(nvml_injection PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

set(NVMLI_VERSION 1.0)
set(NVMLI_MAJOR_VERSION 1)
set_target_properties(
    nvml_injection
    PROPERTIES
        VERSION
        ${NVMLI_VERSION}
        SOVERSION
        ${NVMLI_MAJOR_VERSION}
)

install(
    TARGETS
        nvml_injection
    ARCHIVE DESTINATION ${DCGM_TESTS_APP_DIR} COMPONENT Tests
    LIBRARY DESTINATION ${DCGM_TESTS_APP_DIR}
        PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
        COMPONENT Tests
    RUNTIME DESTINATION ${DCGM_TESTS_APP_DIR}
        PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
        COMPONENT Tests
)

add_subdirectory(tests)
